package org.mm4juser.controller;

import jakarta.annotation.Resource;
import org.mm4juser.entity.DTO.AvatarChangeDTO;
import org.mm4juser.service.UserService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

//ua = user-avator
@RestController
public class AvatarUploadController {
	@Resource
	private UserService userService;
	
	@PostMapping("ua/upload")
	public ResponseEntity<?> uploadAvatar(
		@RequestParam
		MultipartFile newAvatar,
		@RequestParam
		String email) throws IOException {
		AvatarChangeDTO avatarChangeDTO = new AvatarChangeDTO();
		avatarChangeDTO.setNewAvatar(newAvatar);
		avatarChangeDTO.setEmail(email);
		return userService.changeAvatar(avatarChangeDTO);
	}
}
